{layout name="public/layout" /}
{include file='yxnavbar'}


<div class="main">
    <ul class="nav nav-tabs">
        <li><a href="{php echo createWebUrl('Lt_main',array('themeid'=>$themeid));}" >奖项列表</a></li>
        {if $lottery_items_total<6}
        <li><a href="{php echo createWebUrl('Lt_main', array('ac' =>'add','themeid'=>$themeid));}" >新增奖项</a></li>
        {/if}
        <li><a href="{php echo createWebUrl('Lt_chance', array('ac' =>'display','themeid'=>$themeid));}" >抽奖机会</a></li>
        <li {if $do == 'Lt_winning'}class="active"{/if}><a href="{php echo createWebUrl('Lt_winning', array('ac' =>'display','themeid'=>$themeid));}" >中奖记录</a></li>
    </ul>
    {if $ac == "display"}
    <div class="panel panel-info">
        <div class="panel-heading">筛选 共{$total}条</div>
        <div class="panel-body">
            <form action="./index.php" method="get" class="form-horizontal" role="form">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="{$_P['m']}" />
                <input type="hidden" name="do" value="{$do}" />
                <input type="hidden" name="ac" value="search" />
                <input type="hidden" name="themeid" value="{$themeid}" />
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">关键字</label>
                    <div class="col-sm-9 col-xs-9 col-md-9">
                        <input class="form-control" name="nickname" placeholder="输入微信昵称" type="text" value="{$_P['nickname']}">
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">浏览时间</label>
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        {php echo view_form_field_daterange('createtime', array('start_day' => date('Y-m-d', $start_day), 'end_day' => date('Y-m-d', $end_day),));}
                    </div>
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        <button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
                        <input type="hidden" name="__token__" value="{$Request.token}"/>
                    </div>
                </div>
            </form>
        </div>
    </div>
    {/if}
    <!--  列表框  -->
    {if $ac =='display' || $ac =='search'}
    <div class="tab-content">
        <div class="panel panel-default">
            <div class="panel-body table-responsive">
                <table class="table table-hover">
                    <thead class="navbar-inner">
                    <tr>
                        <th width="50">ID</th>
                        <th>客户头像</th>
                        <th>微信昵称</th>
                        <th>姓名</th>
                        <th>电话</th>
                        <th>奖项</th>
                        <th>奖品名称</th>
                        <th>奖品图片</th>
                        <th>领取操作</th>
                        <th>总操作次数</th>
                        <th>剩余操作次数</th>
                        <th>状态</th>
                        <th>时间</th>
                        <th style="width:80px; text-align:right;">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $list $item}
                    <tr>
                        <td>{$item['lr_id']}</td>
                        <td><img src="{php echo tomedia($item['avatar']);}" width="28" style="bsection-radius: 3px;"></td>
                        <td>{$item['nickname']}</td>
                        <td>{$item['username']}</td>
                        <td>{$item['mobile']}</td>
                        <td>{$item['ltt_title']}</td>
                        <td>{$item['ltp_name']}</td>
                        <td><img src="{php echo tomedia($item['ltp_img']);}" width="28" style="bsection-radius: 3px;"></td>
                        <td>{$receive_list[$item['receive_key']]}</td>
                        <td>{$item['receive_todo_num']}</td>
                        <td>{$item['receive_remain_num']}</td>
                        <td>
                            {if $item['status']==2}
                            <span class="label label-warning">任务未完成</span>
                            {elseif $item['status']==1}
                            <span class="label label-success">待兑换</span>
                            {elseif $item['status']==3}
                            <span class="label label-info">已兑换</span>
                            {/if}
                        </td>
                        <td>{$item['created_at']}</td>
                        <td>
                            {if $item['status']==2 || $item['status']==1}
                            <a class="btn btn-primary btn-sm" style="width: 35px"
                               onclick="delLotteryChance(this)" data-remain="{$item['receive_remain_num']}"
                               data-themeid="{$themeid}" data-id="{$item['lr_id']}" data-status="{{$item['status']}}" title="发放奖品" data-toggle="tooltip" data-placement="top"><i class="fa fa-pencil-square-o"> </i></a>
                            {/if}
                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    {/if}
</div>

{if $ac =='display'}
{$pager}
{/if}
<script type="text/javascript">
    function drop_confirm(msg, url){
        if(confirm(msg)){
            window.location = url;
        }
    }
    // 发放奖品
    function sendLotteryReceive(e) {
        let lr_id = e.getAttribute("data-id");
        let status = e.getAttribute("data-status");
        let msg = '';
        if (status==2){
            msg = '该用户领取次数未满足，您确定发放奖品吗？';
        }
        if (status==3){
            msg = '您确定给用户兑换奖品吗？';
        }
        let ac = 'prize';
        let themeid = e.getAttribute("data-themeid");
        let postUrl ="{php echo createWebUrl('Lt_winning');}";
        layer.msg(msg,{
            btn:['确定','取消'],
            yes:function (index) {
                $.ajax({
                    url:postUrl,
                    dataType:'json',
                    method:'post',
                    data: {lr_id:lr_id,themeid:themeid,ac:ac},
                    success:function (e) {
                        console.log(e)
                        let res = e.message;
                        let code = res.code;
                        let msg = res.msg;
                        if (code!=200){
                            layer.msg(msg);
                        }else{
                            layer.msg(msg);
                            location.reload();
                        }
                    },
                    fail:function (err) {
                        console.log(err)
                    }
                });
            }
        });
    }
</script>
